//
//  ReportSpamViewController.m
//  GolfFriend
//
//  Created by Vescky on 14-5-18.
//  Copyright (c) 2014年 vescky.org. All rights reserved.
//

#import "ReportSpamViewController.h"
#import "AppsEngine.h"
#import "UserSession.h"
#import "SVProgressHUD.h"

@interface ReportSpamViewController () {
    NSString *reportReason;
}
@end

@implementation ReportSpamViewController
@synthesize recordId,reportType;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [super customBackButton];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)resetRadio {
    btn1.selected = NO;
    btn2.selected = NO;
    btn3.selected = NO;
    btn4.selected = NO;
    btn5.selected = NO;
}

- (IBAction)btnAction:(id)sender {
    UIButton *btn = (UIButton*)sender;
    if (btn.tag < 105) {
        //选择
        reportReason = btn.titleLabel.text;
        [self resetRadio];
        UIButton *btnRadio = (UIButton*)[self.view viewWithTag:btn.tag + 100];
        btnRadio.selected = YES;
    }
    else {
        //发送
        if (reportReason.length < 1) {
            [SVProgressHUD showErrorWithStatus:@"请选择举报的原因!"];
            return;
        }
        NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:recordId,@"articleId",
                                       reportType,@"type",
                                       reportReason,@"reason",
                                       [[UserSession shareUserSession] getUserId],@"fromId", nil];
        [SVProgressHUD showWithStatus:@"正在提交..."];
        [[AppsEngine shareAppsEngine] submitRequest:@"gfReportSpam" param:params onCompletion:^(id jsonResponse) {
            [SVProgressHUD dismiss];
            [SVProgressHUD showSuccessWithStatus:@"感谢您的举报！"];
            [self performSelector:@selector(goBack) withObject:nil afterDelay:1.0];
        } onError:^(NSError *error) {
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:@"提交失败!"];
        } method:@"GET"];
    }
}

- (void)goback {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
